#include <stdio.h>
#include <malloc.h>

typedef struct node *node_ptr;

struct node {
    int element;
    node_ptr next;
};

typedef node_ptr STACK;

//? S is the header? sentinel
int is_empty(STACK S) {
    return (S->next == NULL);
}

void fatal_error(char *str) {
}

void error(char *str) {
}

STACK create_stack(void) {
    STACK S;
    S = (STACK) malloc(sizeof(struct node));
    if (S == NULL) {
        fatal_error("Out of space!!!");
    }
    return S;
}

//? initial STACK, just header's next is NULL
void make_null(STACK S) {
    if (S != NULL) {
        S->next = NULL;
    } else {
        error("Must use create_stack first");
    }
}

//? just linked list front insert function
void push(int x, STACK S) {
    node_ptr tmp_cell;
    tmp_cell = (node_ptr) malloc(sizeof(struct node));
    if (tmp_cell == NULL) {
        fatal_error("Out of space!!!");
    } else {
        tmp_cell->element = x;
        tmp_cell->next = S->next;
        S->next = tmp_cell;
    }
}

//? examining top is the first element of list
//? S is the header
int top(STACK S) {
    if (is_empty(S)) {
        error("Empty stack");
    } else {
        return S->next->element;
    }
}

void pop(STACK S) {
    node_ptr first_cell;
    if (is_empty(S)) {
        error("Empty stack");
    } else {
        first_cell = S->next;
        S->next = S->next->next;
        free(first_cell);
    }
}

int main() {
    printf("Hello, World!\n");
    return 0;
}
